package com.itfreer.gis.locus.data;


import com.alibaba.dubbo.config.annotation.Service;
import com.itfreer.form.api.BaseDao;
import com.itfreer.form.api.BaseServiceImp;
import com.itfreer.gis.locus.data.dao.LocusWorkDao;
import com.itfreer.gis.locus.data.dto.WorkSitutationDTO;
import com.itfreer.gis.locus.data.entity.LocusWorkEntity;
import com.itfreer.gis.locus.data.vo.WorkSitutationVO;
import com.itfreer.utils.ResponseEntity;
import com.itfreer.utils.json.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 定义巡护任务实现类
 */
@Component
@Service(interfaceClass = LocusWorkService.class, path = "locuswork")
public class LocusWorkServiceImp extends BaseServiceImp<LocusWorkEntity> implements LocusWorkService {

	@Autowired
	private LocusWorkDao dao;

	@Override
	protected BaseDao<LocusWorkEntity> getDao() {
		return dao;
	}
	
	/**
	 * 是否为租户实体对象
	 */
	@Override
	protected boolean isTenant() {
		return false;
	}


	@Override
	public ResponseEntity<WorkSitutationVO> getSituation(WorkSitutationDTO workSitutationDTO) {

		// 轨迹统计
		Map<String, Object> dataMap = dao.getDataSituation(workSitutationDTO);
		String data = JsonUtils.toJSONString(dataMap);
		WorkSitutationVO workSitutationVO = JsonUtils.toBean(data, WorkSitutationVO.class);
		return new ResponseEntity<>(workSitutationVO);
	}

	@Override
	public ResponseEntity<List<WorkSitutationVO>> getDataSituationByState(WorkSitutationDTO workSitutationDTO) {

		List<Map<String, Object>> dataList = dao.getDataSituationByState(workSitutationDTO);
		String data = JsonUtils.toJSONString(dataList);
		List<WorkSitutationVO> workSitutationVOList = JsonUtils.toBeanList(data, WorkSitutationVO.class);
		return new ResponseEntity<>(workSitutationVOList);
	}
}
